﻿using RuleJudge.RuleData;
using SLANCommon;
using SLANCommon.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace RuleJudge.Judge
{
    public class HEV : BaseJudge
    {
        /// <summary>
        /// 构造函数，需要定义项目类型，管，通道信息
        /// </summary>
        public HEV()
        {
            Type = EProjectType.AQ;
            TubesNo = new List<int>() { 1, 1, 1, 1, 2, 2, 2 };
            ChannelsNo = new List<int>() { 1, 2, 3, 4, 1, 2, 3 };
        }
        /// <summary>
        /// 判断逻辑
        /// 规则中只有结论（Conclusion）和自定义结果（CustomResults）可以回传到SLAN软件，其他数据都是为了编辑规则得出结论用的，不能回传。
        /// </summary>
        /// <param name="samples">样本列表</param>
        /// <returns>非空：SLAN会弹出内容信息框，进行提示</returns>
        public override string Judge(List<Sample> samples)
        {
            //在结果判断之前，先检查是否有需要判断的样本
            if (samples.Count == 0) return "无判断样本！";

            //2. 阴性对照的判读
            List<Sample> NegativeList = samples.Where(s => s.Type == SampleType.Negative).ToList();
            foreach (Sample sample in NegativeList)
            {
                bool NegativeIC = sample.Targets.Where(s=>s.Result.Ct > 35).Count() == sample.Targets.Count;
                sample.Conclusion.Add(new Conclusion() { Content = NegativeIC == true ? "合格" : "不合格" });
            }
            //3. 阳性对照的判读
            List<Sample> PositiveList = samples.Where(s => s.Type == SampleType.HighPositive).ToList();
            foreach (Sample sample in PositiveList)
            {
                bool PositiveIC = sample.Targets.Where(s => s.Result.Ct < 35).Count() == sample.Targets.Count;
                sample.Conclusion.Add(new Conclusion() { Content = PositiveIC == true ? "合格" : "不合格" });
            }

            int FAM = 0;
            int VIC = 1;
            int ROX = 2;
            int CY5 = 3;

            List<Sample> UnknownList = samples.Where(s => s.Type == SampleType.Unknown).ToList();   //取出所有“待测样本”
            foreach (Sample sample in UnknownList)
            {
                if (sample.Tubes[0].Targets[FAM].Result.Ct < 35 && sample.Tubes[0].Targets[CY5].Result.Ct < 35 && sample.Tubes[0].Targets[VIC].Result.Ct > 35
                    && sample.Tubes[1].Targets[FAM].Result.Ct > 35 && sample.Tubes[1].Targets[VIC].Result.Ct > 35)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "A" });
                }
                if (sample.Tubes[0].Targets[FAM].Result.Ct > 35 && sample.Tubes[0].Targets[CY5].Result.Ct < 35 && sample.Tubes[0].Targets[VIC].Result.Ct < 35
                    && sample.Tubes[1].Targets[FAM].Result.Ct > 35 && sample.Tubes[1].Targets[VIC].Result.Ct > 35)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "B" });
                }
                if (sample.Tubes[0].Targets[FAM].Result.Ct > 35 && sample.Tubes[0].Targets[CY5].Result.Ct < 35 && sample.Tubes[0].Targets[VIC].Result.Ct > 35
                    && sample.Tubes[1].Targets[FAM].Result.Ct < 35 && sample.Tubes[1].Targets[VIC].Result.Ct > 35)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "C" });
                }
                if (sample.Tubes[0].Targets[FAM].Result.Ct > 35 && sample.Tubes[0].Targets[CY5].Result.Ct < 35 && sample.Tubes[0].Targets[VIC].Result.Ct > 35
                    && sample.Tubes[1].Targets[FAM].Result.Ct > 35 && sample.Tubes[1].Targets[VIC].Result.Ct < 35)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "D" });
                }
                if (sample.Tubes[0].Targets[FAM].Result.Ct > 35 && sample.Tubes[0].Targets[CY5].Result.Ct > 35 && sample.Tubes[0].Targets[VIC].Result.Ct > 35 && sample.Tubes[0].Targets[ROX].Result.Ct > 35
                    && sample.Tubes[1].Targets[FAM].Result.Ct > 35 && sample.Tubes[1].Targets[VIC].Result.Ct > 35 && sample.Tubes[1].Targets[ROX].Result.Ct > 35)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "阴性" });
                }

                if (sample.Conclusion.Count == 0)
                {
                    sample.Conclusion.Add(new Conclusion() { Content = "不可判" });
                }
            }

            return string.Empty;
        }
    }
}
